package com.jiahua.admin.biz.action.category;

import java.util.List;

import org.apache.log4j.Logger;

import com.jiahua.admin.biz.service.InventoryCategoryService;
import com.jiahua.user.biz.model.InventoryCategory;
import com.jiahua.utils.string.StringUtil;
import com.opensymphony.xwork2.ActionSupport;

public class CategorySaveAction extends ActionSupport {

	private static final long serialVersionUID = 1995837929741067312L;

	Logger log = Logger.getLogger(CategorySaveAction.class.getClass());

	private String categoryName;
	private String description;

	private List<InventoryCategory> inventoryCategoryList;

	private InventoryCategoryService inventoryCategoryService;

	public void setInventoryCategoryList(List<InventoryCategory> inventoryCategoryList) {
		this.inventoryCategoryList = inventoryCategoryList;
	}
	
	public List<InventoryCategory> getInventoryCategoryList() {
		return inventoryCategoryList;
	}

	public void setInventoryCategoryService(InventoryCategoryService inventoryCategoryService) {
		this.inventoryCategoryService = inventoryCategoryService;
	}

	public String getCategoryName() {
		return categoryName;
	}

	public void setCategoryName(String categoryName) {
		this.categoryName = categoryName;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@Override
	public String execute() throws Exception {

		InventoryCategory inventoryCategory = new InventoryCategory();
		inventoryCategory.setCategoryName(categoryName);
		inventoryCategory.setFlag((short) 1);

		inventoryCategory.setDescription(StringUtil.regularExpressionsOfHTML(description));

		inventoryCategoryService.saveInventoryCategory(inventoryCategory);
		
		inventoryCategoryList = getCategoryList();
		
		log.info(" >>> inventoryCategoryList.size() : " + inventoryCategoryList.size());

		return super.execute();
	}

	private List<InventoryCategory> getCategoryList() {
		List<InventoryCategory> list = inventoryCategoryService.listInventoryCategory();
		System.out.println("list.size() : " + list.size());
		return list;
	}
	
	
}
